<?php

namespace App\Http\Controllers;

use App\Models\Admin;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\ResetPasswordRequest;

class AdminController extends CommonController
{
    /**
     * 获取修改密码页面
     */
    public function getResetPassword()
    {
        return view('admin.resetpassword')->with("actions", $this->actions);
    }

    public function postResetPassword(ResetPasswordRequest $request){
        $data = $request->input();
        $session = session()->all();
//                dd($data['oldpassword']);exit;
       $admin =  Admin::where('id', $session['user_role']->id)->first();

        if(md5($data['oldpassword'])!=$admin->password){
            return AjaxCallbackMessage('原密码输入错误,密码修改失败',false);
        }

        Admin::where('id', $session['user_role']->id)->update(['password'=>md5($data['newpassword'])]);

        return AjaxCallbackMessage('密码修改成功',true, url('home'));
    }
}
